<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> 讨论列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="/static/hAdmin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/static/hAdmin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- Sweet Alert -->
    <link href="/static/hAdmin/css/plugins/sweetalert/sweetalert.css?v4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/animate.css" rel="stylesheet">
    <!--<link href="/static/hAdmin/css/style.css?v=4.1.0" rel="stylesheet">-->
    <link href="/static/hAdmin/css/style3.css?v4.0" rel="stylesheet">
    <link href="/static/hAdmin/css/plugins/toastr/toastr.min.css" rel="stylesheet">

    <style>
        .addList {
            padding: 10px 30px 10px 30px;
            height: 150px;
            margin-top: 3px
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight blog">
    <span id="gloUrl" style="display: none"></span>
    <button data-toggle="modal" data-target="#myModal" id="causeBtn" style="display: none"></button>
    <div class="row">
        <div class="col-sm-12">

            <div class="ibox">
                <div class="ibox-title" style="height: 55px;">
                    <h5>全部讨论</h5>
                    <div class="ibox-tools" >
                        <div class="text-center">

                        </div>

                    </div>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">

                        <div class="col-md-11 form-inline">
                            <div class="input-group col-xs-5">
                                <input type="text" placeholder="请根据 讨论名称 进行关键词匹配" id="searchKey"
                                       class="input-sm form-control">
                            </div>
<!--                            <div class="input-group adminFun">-->
<!--                                <select class="form-control" id="status" value="3">-->
<!--                                    <option value="" class="form-control">全部</option>-->
<!--                                    <option value="1" class="form-control">正常</option>-->
<!--                                    <option value="2" class="form-control">驳回</option>-->
<!--                                </select>-->

<!--                            </div>-->
                            <div class="input-group">
                                <button type="button" class="btn btn-sm btn-primary"
                                        id="getByKeywords">搜索</button>
                            </div>
                        </div>
                    </div>

                    <!--    讨论列表 -->
                    <div class="row" id="listBody">


                    </div>
                    <!--                        页码控制-->
                    <div id="pageHelper" ajaxUrl="www.baidu.com" currentPage="1">
                        <div class="pageBottom col-xs-10 col-xs-offset-1" style="margin-top: 20px">
                            <nav aria-label="...">
                                <ul class="pager">
                                    <li class="previous disabled"><a href="javascript:void(0)"><span aria-hidden="true">&larr;</span>
                                        Older</a></li>
                                    <li>
                                        <span>共</span>
                                        <span id="data_total"></span>
                                        <span>条数据</span>
                                    </li>
                                    <li class="next"><a href="javascript:void(0)">Newer <span
                                            aria-hidden="true">&rarr;</span></a></li>
                                </ul>
                            </nav>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>

</div>
<!--弹出框-->
<div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated bounceInRight" style="min-height: 300px;overflow-y: scroll">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span>
                    <span class="sr-only">关闭</span>
                </button>
                <h4 class="modal-title">驳回原因</h4>
            </div>
            <div class="formListAdd" align="center">
                <div class="modal-body addList">
                    <div class="form-group col-xs-12">
                        <label for="cause">原因</label>
                        <textarea id="cause" rows="5" placeholder="请输入驳回原因......" class="form-control"></textarea>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-success" data-dismiss="modal" id="confirmDel">确定</button>
            </div>
        </div>
    </div>
</div>
<!-- 全局js -->
<script src="/static/hAdmin/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/hAdmin/js/bootstrap.min.js?v=3.3.6"></script>
<!-- Sweet alert -->
<script src="/static/hAdmin/js/plugins/sweetalert/sweetalert.min.js"></script>

<!-- 自定义js -->
<script src="/static/hAdmin/js/content.js?v=1.0.0"></script>
<!--    分页js -->
<!--<script src="/static/wmmJs/public/PageHelper.js"></script>-->
<script src="/static/hAdmin/js/plugins/toastr/toastr.min.js"></script>
<script src="/static/js/GloJs.js"></script>
<script>
$(function (){
    let Glo_BaseUrl = $("#gloUrl").attr("gloUValue")
    let Glo_user = localStorage.getItem("userId")
    let currentPage = $("#pageHelper").attr("currentPage");
    //获取列表
    function getList(num){
        let total = 0;//总数
        let pageSize = 6;//每页条数
        let html_dom = $("#listBody")
        let searchKey = $("#searchKey").val()
        if ( num === 1){
            searchKey = ""
            $("#searchKey").val("")
        }

       let role = getRole()
        if (role !== 1){
            $("#status").val("1")
        }
        $.ajax({
            url: Glo_BaseUrl + "/tArticle/list",
            type: "get",
            data: {
                "pageSize": pageSize,
                "pageNum": currentPage,
                "searchKey":searchKey,
                "status":$("#status").val(),
            },
            success: function (data) {
                let ListStr = ''
                total = data.total
                for (let i = 0; i < data.list.length; i++) {
                    let item = data.list[i]
                    let delBtn = ``

                        delBtn = `  <button class="btn btn-danger pull-right toDelete adminFun" id="toDelete_${item.id}">删除</button>`

                    ListStr +=
                       `<div class="col-lg-4" >
            <div class="ibox" style="height: 280px;">
                <div class="ibox-content" >
封面：   <img style="width: 100px;height: 100px;" src="${item.pic}" alt="">
                    <a href="javascript:void(0)" class="articleTitle btn-link" thisId="${item.id}" >
                        <h2 style="white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
">
                         标题：   ${item.title}
                        </h2>
                    </a>
                    <div class="small m-b-xs">
                      发表用户：  <strong>${item.userName}</strong> <span class="text-muted"><i class="fa fa-clock-o"></i>${item.createTime}</span>
                    </div>
                    <p>
                  内容：   ${item.content}
                    </p>
                    <div class="row">
                        <div class="col-md-6">
                            <h5>标签：</h5>
                            <button class="btn btn-primary btn-xs" type="button">${item.typeName}</button>
                        </div>
                        <div class="col-md-6">
                            <div class="small text-right">
                                <h5>状态：</h5>
                                <div> <i class="fa fa-comments-o"> </i> ${item.commentNum} 评论 </div>
                                <i class="fa fa-eye"> </i> ${item.readNum} 浏览
                            </div>
                        </div>
                    </div>
                    <div class="row marT10">
                  `+delBtn+`
                    </div>
                </div>
            </div>
        </div>
                `
                }
                if (data.code !== 500) {
                    html_dom.html("")
                    html_dom.append(ListStr)
                } else {
                    alert("获取失败")
                }
                total = data.total
                getRoleSetMenu()
                $("#data_total").html(data.total);
                //下一页
                $('.next').unbind().click(function () {
                    if (currentPage * pageSize >= total) {
                        toastr.error("已经是最后一页了！", '提醒')
                    } else {
                        currentPage++;
                        $("#pageHelper").attr("currentPage", currentPage);
                        if (currentPage > 0) {
                            $(".previous").removeClass("disabled")
                        }
                        $(".project-list").addClass("animated bounceOutLeft")
                        setTimeout(function () {
                            $(".project-list").removeClass("animated bounceOutLeft").addClass("animated bounceInRight")
                        }, 500)
                        getList(2)
                    }
                });
                //上一页
                $('.previous').unbind().click(function () {
                    currentPage--;
                    $("#pageHelper").attr("currentPage", currentPage);
                    if (currentPage === 0) {
                        currentPage = 1;
                        $("#pageHelper").attr("currentPage", currentPage);
                        $(".previous").addClass("disabled");
                    } else {
                        $(".project-list").addClass("animated bounceOutRight")
                        setTimeout(function () {
                            $(".project-list").removeClass("animated bounceOutRight bounceInRight").addClass("animated bounceInLeft")
                        }, 500)
                        getList(2)
                    }
                });
                //查看详情
                $(".seeRentDetail").unbind().click(function () {
                    localStorage.setItem("id", $(this).attr("rentId"));
                });
                //驳回讨论
                $(".toDelete").unbind().click(function () {
                    localStorage.setItem("id", $(this).attr("id").split("toDelete_")[1]);
                    let id = localStorage.getItem("id")
                    swal({
                        title: "您确定要删除讨论吗",
                        text: "删除的讨论不可恢复！",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "删除",
                        closeOnConfirm: false
                    }, function () {

                        $.ajax({
                            url: Glo_BaseUrl + "/tArticle/del",
                            type: "post",
                            data: {
                                id: id,
                                status:2,
                                userId:Glo_user,

                            },
                            success: function (data) {
                                if (data.code === 200){
                                    swal("删除成功！", "该讨论已被删除。", "success");
                                }else {
                                    swal("删除失败！", "删除失败。", "error");
                                }

                                getList(2)
                            },
                            error: function () {
                                alert("服务器异常！network error！")
                            }
                        })

                    });
                });
                //讨论详情
                $(".articleTitle").unbind().click(function (){
                   localStorage.setItem("id",$(this).attr("thisId"))
                    window.location.href = Glo_BaseUrl +  '/web/forumDetail'
                })
            },
            error: function () {
                alert("服务器异常！network error！")
            }
        });


    }
    getList()
    $("#getByKeywords").click(function (){
        getList();
    })
    //确认驳回
    $("#confirmDel").click(function (){
        let id = localStorage.getItem("id")
        $.ajax({
            url: Glo_BaseUrl + "/tArticle/edit",
            type: "post",
            data: {
                id: id,
                status:2,
                userId:Glo_user,
                cause:$("#cause").val()
            },
            success: function (data) {
            if (data.code === 200){
                swal("驳回成功！", "该讨论已被驳回。", "success");
            }else {
                swal("驳回失败！", "驳回失败。", "error");
            }

                getList(2)
            },
            error: function () {
                alert("服务器异常！network error！")
            }
        })
    })
})
</script>
</body>
</html>
